#ifndef P2PCHAT_H
#define P2PCHAT_H

#include <QList>
#include <QObject>
#include <QMutex>
#include <QMutexLocker>
#include <QObject>
#include <QIcon>
#include <QColor>

#include "AliveSender.h"
#include "AliveConsumer.h"
#include "MessagesConsumer.h"
#include "User.h"
#include "Command.h"
#include "AliveCommand.h"
#include "UserIdentityFormImpl.h"
#include "SettingsExpert.h"
#include "Qrm3Controller.h"
#include "SettingsGlobalResource.h"
/**
 * Controller for p2p intranet chat [Singleton]
 */
class P2PChat : public QObject
{
	Q_OBJECT

private:
	static P2PChat *instance;
	User *mySelf;
	MessagesConsumer *msgConsumer;
	AliveSender *as;
	AliveConsumer *ac;
	QMap<QString, User *> *users;			//knowed users
	QMap<QByteArray, Command *> *commands;	//knowed commands
	QMutex *usersMutex;
	bool isConnected;
	//SettingsExpert *se;		//the same instance of qrm3controller class 
	QTimer *connectionTimer;
	int connectionWarmup;
	
	void addKnownUsers();
	void initCommands();
	
public:
	P2PChat();
	static P2PChat* getInstance();
	User* getMySelf();
	QMap<QString, User *> * getUsers();
	void setMySelf(User *u);
	QMap<QByteArray, Command *> * getCommands();
	QMutex* getUserMutex();
	void setConnected(bool state);

public slots:
	void startChat();
	void stopChat();
	void saveIdentity();
	void warmupTimeout();
	void addConnectedUser(User *s);
	void processUserDisconnected(User *s);
};
#endif
